package com.itsu.admin.controller;

import com.itsu.admin.model.PageReq;
import com.itsu.admin.model.ListResult;
import com.itsu.admin.mvc.Result;
import com.itsu.admin.service.TaskService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author Jerry.su
 * @Date 2022/1/2 16:54
 */
@RestController
@RequestMapping("/task")
public class TaskController {

    @Resource
    private TaskService taskService;

    @GetMapping("/list")
    public ListResult list(int page, int limit) {
        return taskService.list(new PageReq(page, limit));
    }

    @PostMapping("/changeStatus")
    public Result stop(String jobId, int status, String registerHost) {
        return taskService.changeStatus(jobId, status, registerHost);
    }

    @GetMapping("/run/{jobId}/{registerHost}")
    public Result run(@PathVariable("jobId") String jobId, @PathVariable("registerHost") String registerHost) {
        return taskService.runJob(jobId, registerHost);
    }

    @GetMapping("/search")
    public Result search(String key) {
        return taskService.search(key);
    }
}
